package com.xuelang.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.xuelang.pipeline.entry.common.utils.QuantityDeserializer;
import io.kubernetes.client.custom.Quantity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * <p>Jackson配置类</p>
 *
 * @author : yixin.lys
 * @date : 2024-07-16 15:10
 **/
@Configuration
public class JacksonConfig {

    @Bean
    public ObjectMapper objectMapper() {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();

        // 创建SimpleModule并添加Quantity的反序列化器
        SimpleModule module = new SimpleModule();
        module.addDeserializer(Quantity.class, new QuantityDeserializer());

        // 注册JavaTimeModule以处理Java 8的日期和时间类型
        builder.modules(module, new JavaTimeModule());

        return builder.build();
    }

}
